package com.qk.management.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.qk.common.constant.RedisCacheConstants;
import com.qk.domain.business.BusinessCountDO;
import com.qk.domain.clue.ClueCountDO;
import com.qk.management.annotation.RedisCacheAnnotation;
import com.qk.management.mapper.BusinessMapper;
import com.qk.management.mapper.ClueMapper;
import com.qk.management.service.ReportService;
import com.qk.vo.report.OverviewVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * @Author:gzc
 * @Date: 2025/10/07 19:44
 * @Description:
 */
@Service
@Slf4j
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ClueMapper clueMapper;

    @Autowired
    private BusinessMapper businessMapper;

    @RedisCacheAnnotation(
            keyPrefix = RedisCacheConstants.CACHE_PORTAL_KEY_PREFIX,
            expire = 24 * 60,
            expireTimeUnit = TimeUnit.MINUTES
    )
    @Transactional(rollbackFor = Exception.class)
    @Override
    public OverviewVO queryOverview() {
        ClueCountDO clueCountDO = clueMapper.queryClue();
        BusinessCountDO businessCountDO = businessMapper.queryBusiness();
        OverviewVO overviewVO = BeanUtil.copyProperties(clueCountDO, OverviewVO.class);
        BeanUtil.copyProperties(businessCountDO, overviewVO);
        log.info("查询数据库中的数据: {}, 缓存到redis中", overviewVO);
        return overviewVO;
    }
}
